package com.jjb.www.ui.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.ViewPager;

import android.os.Bundle;

import com.hjq.base.FragmentPagerAdapter;
import com.jjb.www.R;
import com.jjb.www.app.AppActivity;
import com.jjb.www.app.AppFragment;
import com.jjb.www.bean.BannerBean;
import com.jjb.www.other.AppConfig;
import com.jjb.www.ui.adapter.TabAdapter;
import com.jjb.www.ui.fragment.CourseListFragment;
import com.jjb.www.ui.fragment.LiveRecordingFragment;
import com.jjb.www.ui.fragment.OnDemandRecordingFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * author : Android CRG
 * time   : 2018/10/18
 * desc   : 学习校验记录Live recording
 */
public class VerificationRecordActivity extends AppActivity implements TabAdapter.OnTabListener, ViewPager.OnPageChangeListener{
    private ViewPager mViewPager;
    private TabAdapter mTabAdapter;
    private RecyclerView mTabView;
    private FragmentPagerAdapter<AppFragment<?>> mPagerAdapter;
    private String id_card;
    private String planCode;
    private String trainPostCode;
    private String student_id;
    private String type="1";
    @Override
    protected int getLayoutId() {
        return R.layout.activity_verification_record;
    }

    @Override
    protected void initView() {
        mTabView = findViewById(R.id.rv_home_tab);
        mViewPager = findViewById(R.id.vp_home_pager);
        mPagerAdapter = new FragmentPagerAdapter<>(this);
        mViewPager.addOnPageChangeListener(this);
        mTabAdapter = new TabAdapter(this);
        mTabView.setAdapter(mTabAdapter);
        mTabAdapter.setOnTabListener(this);

    }

    @Override
    protected void initData() {
        id_card = getString("id_card");
        planCode = getString("planCode");
        trainPostCode = getString("trainPostCode");
        student_id = getString("student_id");
        mTabAdapter.addItem("点播课程");
        mTabAdapter.addItem("直播课程");

        mPagerAdapter.addFragment(OnDemandRecordingFragment.newInstance(id_card,planCode,trainPostCode,type), "点播课程");
        mPagerAdapter.addFragment(LiveRecordingFragment.newInstance(id_card,student_id),"直播课程" );
        mViewPager.setAdapter(mPagerAdapter);
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
        if (mTabAdapter == null) {
            return;
        }
        mTabAdapter.setSelectedPosition(position);
    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }

    @Override
    public boolean onTabSelected(RecyclerView recyclerView, int position) {
        mViewPager.setCurrentItem(position);
        return true;
    }
    @Override
    public void onDestroy() {
        super.onDestroy();
        mViewPager.setAdapter(null);
        mViewPager.removeOnPageChangeListener(this);
        mTabAdapter.setOnTabListener(null);
    }
}